
//
//  SizeLabel.m
//  sooc-ios_new
//
//  Created by apple on 16/4/7.
//  Copyright © 2016年 xuguangChao. All rights reserved.
//

#import "SizeLabel.h"

@implementation SizeLabel


-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
           }
    return self;
}

- (CGFloat)labelWithText:(NSString *)text andNum:(NSInteger)number{


    self.text = text;
    self.numberOfLines = number;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    [paragraphStyle setLineSpacing:5];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,text.length)];
    
    self.attributedText = attributedString;
    //调节高度
    CGSize sizes = CGSizeMake(self.frame.size.width, 0);
    
    CGSize labelSize = [self sizeThatFits:sizes];
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, labelSize.height);

    return labelSize.height;
}

//- (void)setTextStr:(NSString *)textStr{
//
//    self.text = textStr;
//    self.numberOfLines = 0;
//    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:textStr];;
//    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
//    [paragraphStyle setLineSpacing:5];
//    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,textStr.length)];
//    
//    self.attributedText = attributedString;
//    //调节高度
//    CGSize sizes = CGSizeMake(self.frame.size.width, 0);
//    
//    CGSize labelSize = [self sizeThatFits:sizes];
//    
//    [self sizeToFit];
//    
//    self.numberOfLines = 2;
//    
//    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, labelSize.height);
//
//    
//}



//-(CGFloat)high{
//    
//    
//    return self.frame.size.height;
//    
//}

@end
